//
//  UIBarButtonItem+Extension.m
//  XinLang(OC)
//
//  Created by 檀志文 on 16/4/19.
//  Copyright © 2016年 ios檀志文. All rights reserved.
//

#import "UIBarButtonItem+Extension.h"

@implementation UIBarButtonItem (Extension)

-(instancetype)init:(NSString *)imageName target:(id)target action:(SEL)action{
    if (self = [super init]) {
        UIButton *btn = [[UIButton alloc]init];
        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]] forState:UIControlStateNormal];
//        [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState:UIControlStateHighlighted];
        [btn sizeToFit];
        [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
        self.init.customView= btn;
    }
    
    return self;
}

 /// 使用类方法
+(UIBarButtonItem *) createBarButtonItem:(NSString *)imageName{
    UIButton *btn = [[UIButton alloc]init];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@",imageName]] forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] forState:UIControlStateHighlighted];
    [btn sizeToFit];
    return  [[UIBarButtonItem alloc]initWithCustomView:btn];
}

@end
